#include<iostream>
#include<pthread.h>
#include<unistd.h>
#include<sys/types.h>
#include<string>
using namespace std;

int gcnt = 100;

void* ThreadRountine(void *args)
{
    
    string threadname = (const char*)args;

    while(true)
    {
        cout << "new thread" << threadname << "pid" << getpid() << "gcnt" << gcnt << endl;
        cout << pthread_self() << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, ThreadRountine, (void*)"thread 1");
    
    //传参
    //pthread_t tid1;
    //pthread_create(&tid, nullptr, ThreadRountine, (void*)"thread 1");

    sleep(3);
    //主线程;
    while(true)
    {
        cout << "main thread" << getpid() << "gcnt:" << gcnt << endl;
        sleep(1);
    }
}